/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package config.Models;

import config.ConfigMacros;
import java.util.HashMap;
import java.util.Map;
import libCore.Util;

/**
 *
 * @author LinhTA
 */
public class Conf_Peg {

    public Map<String, Conf_PegLevel> levels;
    public Map<String, Conf_PegItemGroup> itemGroups;
    public Map<String, Integer> expTrees;
    public Map<String, String> itemTypes;
    public String resbucket;
    public String name;

    public Conf_Peg(Map<String, Object> obj) {
        levels      =   new HashMap<String, Conf_PegLevel>();
        resbucket   =   obj.get(ConfigMacros.PEG_RESBUCKET).toString();
        name        =   obj.get(ConfigMacros.PEG_NAME).toString();
        expTrees    =   new HashMap<String, Integer>();
        itemTypes   =   new HashMap<String, String>();
        itemGroups  =   new HashMap<String, Conf_PegItemGroup>();

        Map<String, Object> exptree = Util.obj2Map(obj.get(ConfigMacros.PEG_EXPTREE));
        for (Map.Entry<String, Object> entry : exptree.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            expTrees.put(string, Integer.parseInt(object.toString()));
        }

        Map<String, Object> item = Util.obj2Map(obj.get(ConfigMacros.PEG_ITEM));
        for (Map.Entry<String, Object> entry : item.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            itemTypes.put( string, String.valueOf( object ) );
        }
        
        Map<String, Object> peg = Util.obj2Map(obj.get(ConfigMacros.PEG_LEVELS));

        for (Map.Entry<String, Object> entry : peg.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            Conf_PegLevel confpeglevel = new Conf_PegLevel(Util.obj2Map(object));

            levels.put(string, confpeglevel);
        }
        
        Map<String, Object> grps = Util.obj2Map(obj.get(ConfigMacros.PEG_ITEMGROUP));
        for (Map.Entry<String, Object> entry : grps.entrySet()) {
            String string = entry.getKey();
            Object object = entry.getValue();

            Conf_PegItemGroup confpegitemGroup = new Conf_PegItemGroup(Util.obj2Map(object));

            itemGroups.put(string, confpegitemGroup);
        }
    }

    public Conf_PegItemGroup getPegItemGroup(int level) {
        Conf_PegItemGroup conf  =   itemGroups.get( String.valueOf( level) );
        return conf;
    }
    
    public Conf_PegLevel getPegLevel(int level) {
        Conf_PegLevel conf = levels.get(String.valueOf( level ) );
        return conf;
    }
}
